﻿using CommandLine;
using CommandLine.Text;
using log4net;
using System;
using System.Threading.Tasks;
using Zbus.Mq;

namespace Zbus.Examples
{ 
    class ConsumerAckExample
    { 

        static void Main(string[] args)
        { 
            Broker broker = new Broker("localhost:15555;localhost:15556");
            var ctrl = new Message();
            ctrl.Topic = "MyTopic";
            ctrl.ConsumeGroup = "MyTopic-ACK";
            ctrl.GroupMask = Protocol.MASK_ACK_REQUIRED; //Group features Bits
            ctrl.GroupAckTimeout = 10 * 1000; //10s

            Consumer c = new Consumer(broker, ctrl); 
            c.ConnectionCount = 1; //Physical connection count
            c.ConsumeTimeout = 10 * 1000;
            
            c.MessageHandler += async (msg, client) => {
                Console.WriteLine(msg); 
                await client.AckAsync(msg); //Confirm of message receipt
            };
            c.Start(); 

            Console.ReadKey();
        }
    }
}
